<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>GSoC2011SfM: D:/Travail/These/Determination caracteristiques camera/GSoC/SfM/src/PointsMatcher.cpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">GSoC2011SfM
   &#160;<span id="projectnumber">0.1</span>
   </div>
   <div id="projectbrief">Google Summer of Code 2011: Structure from motion</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">D:/Travail/These/Determination caracteristiques camera/GSoC/SfM/src/PointsMatcher.cpp</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 <span class="preprocessor">#include &quot;macro.h&quot;</span> <span class="comment">//SFM_EXPORTS</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;opencv2/imgproc/imgproc.hpp&gt;</span>
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <span class="preprocessor">#include &quot;PointsMatcher.h&quot;</span>
<a name="l00007"></a>00007 <span class="preprocessor">#include &quot;PointsToTrack.h&quot;</span>
<a name="l00008"></a>00008 
<a name="l00009"></a>00009 <span class="keyword">namespace </span>OpencvSfM{
<a name="l00010"></a>00010   <span class="keyword">using</span> cv::Mat;
<a name="l00011"></a>00011   <span class="keyword">using</span> cv::Ptr;
<a name="l00012"></a>00012   <span class="keyword">using</span> std::vector;
<a name="l00013"></a>00013   <span class="keyword">using</span> cv::KeyPoint;
<a name="l00014"></a>00014   <span class="keyword">using</span> cv::DMatch;
<a name="l00015"></a>00015   <span class="keyword">using</span> cv::Size;
<a name="l00016"></a>00016   <span class="keyword">using</span> cv::Rect;
<a name="l00017"></a>00017 
<a name="l00018"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a6e28c42636e34e8c29d255202869598b">00018</a>   <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a6e28c42636e34e8c29d255202869598b">PointsMatcher::PointsMatcher</a>( <span class="keyword">const</span> cv::Ptr&lt;cv::DescriptorMatcher&gt;&amp; matcher )
<a name="l00019"></a>00019   {
<a name="l00020"></a>00020     CV_DbgAssert( !matcher.empty( ) );
<a name="l00021"></a>00021     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a> = matcher;
<a name="l00022"></a>00022     INIT_MUTEX( thread_concurr );
<a name="l00023"></a>00023   }
<a name="l00024"></a>00024 
<a name="l00025"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a23808f2edfa41960847075a63d8926ba">00025</a>   <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a6e28c42636e34e8c29d255202869598b">PointsMatcher::PointsMatcher</a>( <span class="keyword">const</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html" title="A class used for matching descriptors that can be described as vectors in a finite-dimensional space...">PointsMatcher</a>&amp; copy )
<a name="l00026"></a>00026   {
<a name="l00027"></a>00027     INIT_MUTEX( thread_concurr );
<a name="l00028"></a>00028     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>=copy.<a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>;
<a name="l00029"></a>00029     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a> = copy.<a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a>-&gt;clone( <span class="keyword">true</span> );
<a name="l00030"></a>00030   }
<a name="l00031"></a>00031 
<a name="l00032"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#ae0ab9bb79ab470ad6bad8c8f52d7ca61">00032</a>   <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#ae0ab9bb79ab470ad6bad8c8f52d7ca61">PointsMatcher::~PointsMatcher</a>( <span class="keywordtype">void</span> )
<a name="l00033"></a>00033   {
<a name="l00034"></a>00034     <span class="comment">//matcher_ is freed thanks to cv::Ptr</span>
<a name="l00035"></a>00035     <span class="comment">//idem for pointCollection_</span>
<a name="l00036"></a>00036   }
<a name="l00037"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a78015799f672c637623a5a44da3f252c">00037</a>   <span class="keyword">const</span> cv::KeyPoint &amp;<a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a78015799f672c637623a5a44da3f252c">PointsMatcher::getKeypoint</a>( <span class="keywordtype">int</span> numKey )<span class="keyword"> const</span>
<a name="l00038"></a>00038 <span class="keyword">  </span>{
<a name="l00039"></a>00039     CV_DbgAssert( <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>.size( )&gt;0 );
<a name="l00040"></a>00040     <span class="keywordflow">return</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>[ 0 ]-&gt;getKeypoint( numKey );
<a name="l00041"></a>00041   }
<a name="l00042"></a>00042 
<a name="l00043"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a0f5001301f3cdd4b24f4495dfe307742">00043</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a0f5001301f3cdd4b24f4495dfe307742">PointsMatcher::add</a>( Ptr&lt;PointsToTrack&gt; pointCollection )
<a name="l00044"></a>00044   {
<a name="l00045"></a>00045     P_MUTEX( thread_concurr );
<a name="l00046"></a>00046     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>.push_back( pointCollection );
<a name="l00047"></a>00047     V_MUTEX( thread_concurr );
<a name="l00048"></a>00048   }
<a name="l00049"></a>00049 
<a name="l00050"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#ac4d214492d8659c36715f79ebb19fc0d">00050</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#ac4d214492d8659c36715f79ebb19fc0d">PointsMatcher::clear</a>( )
<a name="l00051"></a>00051   {
<a name="l00052"></a>00052     P_MUTEX( thread_concurr );
<a name="l00053"></a>00053     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a>-&gt;clear( );
<a name="l00054"></a>00054     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>.clear( );
<a name="l00055"></a>00055     V_MUTEX( thread_concurr );
<a name="l00056"></a>00056   }
<a name="l00057"></a>00057 
<a name="l00058"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a0772137e424d1cd562d6e6600601d917">00058</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a0772137e424d1cd562d6e6600601d917">PointsMatcher::train</a>( )
<a name="l00059"></a>00059   {
<a name="l00060"></a>00060     P_MUTEX( thread_concurr );
<a name="l00061"></a>00061     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a>-&gt;clear( );
<a name="l00062"></a>00062 
<a name="l00063"></a>00063     vector&lt;Mat&gt; pointsDesc;
<a name="l00064"></a>00064     Ptr&lt;PointsToTrack&gt; pointCollection;
<a name="l00065"></a>00065     vector&lt; Ptr&lt; PointsToTrack &gt; &gt;::iterator it =
<a name="l00066"></a>00066       <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>.begin( ),
<a name="l00067"></a>00067       it_end = <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>.end( );
<a name="l00068"></a>00068     <span class="keywordflow">while</span>( it != it_end )
<a name="l00069"></a>00069     {
<a name="l00070"></a>00070       pointCollection = *it;
<a name="l00071"></a>00071       pointCollection-&gt;computeKeypointsAndDesc( <span class="keyword">false</span> );
<a name="l00072"></a>00072 
<a name="l00073"></a>00073       pointsDesc.push_back( pointCollection-&gt;getDescriptors( ) );
<a name="l00074"></a>00074 
<a name="l00075"></a>00075       pointCollection-&gt;free_descriptors();<span class="comment">//save memory...</span>
<a name="l00076"></a>00076 
<a name="l00077"></a>00077       it++;
<a name="l00078"></a>00078     }
<a name="l00079"></a>00079 
<a name="l00080"></a>00080 
<a name="l00081"></a>00081     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a>-&gt;add( pointsDesc );
<a name="l00082"></a>00082     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a>-&gt;train( );
<a name="l00083"></a>00083     V_MUTEX( thread_concurr );
<a name="l00084"></a>00084   }
<a name="l00085"></a>00085 
<a name="l00086"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a4b3d7673ff8e8cdbf1780dda26acd151">00086</a>   <span class="keywordtype">bool</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a4b3d7673ff8e8cdbf1780dda26acd151">PointsMatcher::isMaskSupported</a>( )
<a name="l00087"></a>00087   {
<a name="l00088"></a>00088     <span class="keywordflow">return</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a>-&gt;isMaskSupported( );
<a name="l00089"></a>00089   }
<a name="l00090"></a>00090 
<a name="l00091"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a9afa33e88a49ee4bdee18906e2d82566">00091</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a9afa33e88a49ee4bdee18906e2d82566">PointsMatcher::match</a>( cv::Ptr&lt;PointsToTrack&gt; queryPoints,
<a name="l00092"></a>00092     std::vector&lt;cv::DMatch&gt;&amp; matches,
<a name="l00093"></a>00093     <span class="keyword">const</span> std::vector&lt;cv::Mat&gt;&amp; masks )
<a name="l00094"></a>00094   {
<a name="l00095"></a>00095     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a0772137e424d1cd562d6e6600601d917">train</a>( );
<a name="l00096"></a>00096 
<a name="l00097"></a>00097     queryPoints-&gt;computeKeypointsAndDesc( <span class="keyword">false</span> );
<a name="l00098"></a>00098 
<a name="l00099"></a>00099     vector&lt;KeyPoint&gt; keyPoints=queryPoints-&gt;getKeypoints( );
<a name="l00100"></a>00100     Mat descMat=queryPoints-&gt;getDescriptors( );
<a name="l00101"></a>00101 
<a name="l00102"></a>00102     CV_DbgAssert( !keyPoints.empty( ) );
<a name="l00103"></a>00103     CV_DbgAssert( !descMat.empty( ) );
<a name="l00104"></a>00104 
<a name="l00105"></a>00105     P_MUTEX( thread_concurr );
<a name="l00106"></a>00106     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a>-&gt;match( descMat, matches, masks );
<a name="l00107"></a>00107     V_MUTEX( thread_concurr );
<a name="l00108"></a>00108 
<a name="l00109"></a>00109     queryPoints-&gt;free_descriptors();
<a name="l00110"></a>00110   }
<a name="l00111"></a>00111 
<a name="l00112"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#aec0926024b3974529ca69c028d237e42">00112</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#aec0926024b3974529ca69c028d237e42">PointsMatcher::knnMatch</a>(  Ptr&lt;PointsToTrack&gt; queryPoints,
<a name="l00113"></a>00113     vector&lt;vector&lt;DMatch&gt; &gt;&amp; matches, <span class="keywordtype">int</span> knn,
<a name="l00114"></a>00114     <span class="keyword">const</span> vector&lt;Mat&gt;&amp; masks, <span class="keywordtype">bool</span> compactResult )
<a name="l00115"></a>00115   {
<a name="l00116"></a>00116     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a0772137e424d1cd562d6e6600601d917">train</a>( );
<a name="l00117"></a>00117 
<a name="l00118"></a>00118     queryPoints-&gt;computeKeypointsAndDesc( <span class="keyword">false</span> );
<a name="l00119"></a>00119 
<a name="l00120"></a>00120     vector&lt;KeyPoint&gt; keyPoints=queryPoints-&gt;getKeypoints( );
<a name="l00121"></a>00121     Mat descMat=queryPoints-&gt;getDescriptors( );
<a name="l00122"></a>00122 
<a name="l00123"></a>00123     CV_DbgAssert( !keyPoints.empty( ) );
<a name="l00124"></a>00124     CV_DbgAssert( !descMat.empty( ) );
<a name="l00125"></a>00125 
<a name="l00126"></a>00126     P_MUTEX( thread_concurr );
<a name="l00127"></a>00127     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a>-&gt;knnMatch( descMat, matches, knn, masks, compactResult );
<a name="l00128"></a>00128     V_MUTEX( thread_concurr );
<a name="l00129"></a>00129 
<a name="l00130"></a>00130     queryPoints-&gt;free_descriptors();
<a name="l00131"></a>00131   }
<a name="l00132"></a>00132 
<a name="l00133"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a2185af4c6fc8901cdc3f37b8a9c85822">00133</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a2185af4c6fc8901cdc3f37b8a9c85822">PointsMatcher::radiusMatch</a>( cv::Ptr&lt;PointsToTrack&gt; queryPoints,
<a name="l00134"></a>00134     vector&lt;vector&lt;DMatch&gt; &gt;&amp; matches, <span class="keywordtype">float</span> maxDistance,
<a name="l00135"></a>00135     <span class="keyword">const</span> vector&lt;Mat&gt;&amp; masks, <span class="keywordtype">bool</span> compactResult )
<a name="l00136"></a>00136   {
<a name="l00137"></a>00137     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a0772137e424d1cd562d6e6600601d917">train</a>( );
<a name="l00138"></a>00138 
<a name="l00139"></a>00139     queryPoints-&gt;computeKeypointsAndDesc( <span class="keyword">false</span> );
<a name="l00140"></a>00140 
<a name="l00141"></a>00141     vector&lt;KeyPoint&gt; keyPoints=queryPoints-&gt;getKeypoints( );
<a name="l00142"></a>00142     Mat descMat=queryPoints-&gt;getDescriptors( );
<a name="l00143"></a>00143 
<a name="l00144"></a>00144     CV_DbgAssert( !keyPoints.empty( ) );
<a name="l00145"></a>00145     CV_DbgAssert( !descMat.empty( ) );
<a name="l00146"></a>00146     
<a name="l00147"></a>00147     P_MUTEX( thread_concurr );
<a name="l00148"></a>00148     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a>-&gt;radiusMatch( descMat, matches, maxDistance, masks, compactResult );
<a name="l00149"></a>00149     V_MUTEX( thread_concurr );
<a name="l00150"></a>00150 
<a name="l00151"></a>00151     queryPoints-&gt;free_descriptors();
<a name="l00152"></a>00152   }
<a name="l00153"></a>00153 
<a name="l00154"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a29e94f44fd1726cac6833c233145cf3f">00154</a>   <span class="keywordtype">bool</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a29e94f44fd1726cac6833c233145cf3f">PointsMatcher::empty</a>( )<span class="keyword"> const</span>
<a name="l00155"></a>00155 <span class="keyword">  </span>{
<a name="l00156"></a>00156     <span class="keywordflow">return</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>.empty( ) ||  <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a>-&gt;empty( );
<a name="l00157"></a>00157   }
<a name="l00158"></a>00158 
<a name="l00159"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a30f88f6ce4159fb6539a98768ff071b4">00159</a>   Ptr&lt;PointsMatcher&gt; <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a30f88f6ce4159fb6539a98768ff071b4">PointsMatcher::clone</a>( <span class="keywordtype">bool</span> emptyTrainData )
<a name="l00160"></a>00160   {
<a name="l00161"></a>00161     P_MUTEX( thread_concurr );
<a name="l00162"></a>00162     Ptr&lt;PointsMatcher&gt; outPointMatcher=<span class="keyword">new</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a6e28c42636e34e8c29d255202869598b">PointsMatcher</a>( <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a652ba26d167b0ab2dc27e8087ab8d3cf" title="Algorithm used to find matches...">matcher_</a>-&gt;clone( emptyTrainData ) );
<a name="l00163"></a>00163     <span class="keywordflow">if</span>( !emptyTrainData )
<a name="l00164"></a>00164       outPointMatcher-&gt;pointCollection_=<a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>;
<a name="l00165"></a>00165     V_MUTEX( thread_concurr );
<a name="l00166"></a>00166 
<a name="l00167"></a>00167     <span class="keywordflow">return</span> outPointMatcher;
<a name="l00168"></a>00168   }
<a name="l00169"></a>00169   
<a name="l00170"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a028a13d395eeb91fd0741338b7f036e2">00170</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a028a13d395eeb91fd0741338b7f036e2">PointsMatcher::crossMatch</a>( Ptr&lt;PointsMatcher&gt; otherMatcher,
<a name="l00171"></a>00171     vector&lt;DMatch&gt;&amp; matches,
<a name="l00172"></a>00172     <span class="keyword">const</span> std::vector&lt;cv::Mat&gt;&amp; masks )
<a name="l00173"></a>00173   {
<a name="l00174"></a>00174     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a0772137e424d1cd562d6e6600601d917">train</a>( );
<a name="l00175"></a>00175 
<a name="l00176"></a>00176     <span class="comment">//TODO: for now this function only work with matcher having only one picture</span>
<a name="l00177"></a>00177     CV_DbgAssert( this-&gt;<a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>.size( )==1 );
<a name="l00178"></a>00178     CV_DbgAssert( otherMatcher-&gt;pointCollection_.size( )==1 );
<a name="l00179"></a>00179 
<a name="l00180"></a>00180     <span class="keywordflow">if</span>( matches.empty( ) )
<a name="l00181"></a>00181     {
<a name="l00182"></a>00182       <span class="comment">//as we don&#39;t have matches for img1 -&gt; img2, compute them:</span>
<a name="l00183"></a>00183       this-&gt;<a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a9afa33e88a49ee4bdee18906e2d82566">match</a>( otherMatcher-&gt;pointCollection_[ 0 ], matches, masks );
<a name="l00184"></a>00184     }
<a name="l00185"></a>00185 
<a name="l00186"></a>00186 
<a name="l00187"></a>00187     <span class="comment">//now construct the vector of DMatch, but in the other way ( 2 -&gt; 1 ):</span>
<a name="l00188"></a>00188     vector&lt;DMatch&gt; matchesOtherWay;
<a name="l00189"></a>00189     P_MUTEX( thread_concurr );
<a name="l00190"></a>00190     otherMatcher-&gt;match( <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>[ 0 ], matchesOtherWay, masks );
<a name="l00191"></a>00191     V_MUTEX( thread_concurr );
<a name="l00192"></a>00192     <span class="comment">//now check for reciprocity:</span>
<a name="l00193"></a>00193     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nbPoints=matches.size( );
<a name="l00194"></a>00194     <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;nbPoints; i++ )
<a name="l00195"></a>00195     {
<a name="l00196"></a>00196       DMatch d1=matches[ i ];
<a name="l00197"></a>00197       DMatch d2=matchesOtherWay[ d1.trainIdx ];
<a name="l00198"></a>00198       <span class="keywordflow">if</span>( d2.trainIdx!=d1.queryIdx )
<a name="l00199"></a>00199       {
<a name="l00200"></a>00200         <span class="comment">//remove the current match!</span>
<a name="l00201"></a>00201         nbPoints--;<span class="comment">//because we have a match less!</span>
<a name="l00202"></a>00202         matches[ i ]=matches[ nbPoints ];
<a name="l00203"></a>00203         matches.pop_back( );
<a name="l00204"></a>00204         i--;<span class="comment">//because we have to test this one!</span>
<a name="l00205"></a>00205       }
<a name="l00206"></a>00206     }
<a name="l00207"></a>00207     matchesOtherWay.clear( );
<a name="l00208"></a>00208   }
<a name="l00209"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#aa3ddc09d6225a4c167760f17c2999ae3">00209</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#aa3ddc09d6225a4c167760f17c2999ae3">PointsMatcher::drawMatches</a>( <span class="keyword">const</span> Mat&amp; img1,
<a name="l00210"></a>00210     <span class="keyword">const</span> vector&lt;cv::KeyPoint&gt;&amp; keypoints1,
<a name="l00211"></a>00211     <span class="keyword">const</span> vector&lt;cv::KeyPoint&gt;&amp; keypoints2,
<a name="l00212"></a>00212     <span class="keyword">const</span> vector&lt;cv::DMatch&gt;&amp; matches1to2, Mat&amp; outImg,
<a name="l00213"></a>00213     <span class="keyword">const</span> cv::Scalar&amp; matchColor, <span class="keyword">const</span> cv::Scalar&amp; singlePointColor,
<a name="l00214"></a>00214     <span class="keyword">const</span> std::vector&lt;char&gt;&amp; matchesMask, <span class="keywordtype">int</span> flags )
<a name="l00215"></a>00215   {
<a name="l00216"></a>00216     Size size( img1.cols, img1.rows );
<a name="l00217"></a>00217     <span class="keywordflow">if</span>( flags &amp; cv::DrawMatchesFlags::DRAW_OVER_OUTIMG )
<a name="l00218"></a>00218     {
<a name="l00219"></a>00219       <span class="keywordflow">if</span>( size.width &gt; outImg.cols || size.height &gt; outImg.rows )
<a name="l00220"></a>00220         CV_Error( CV_StsBadSize, <span class="stringliteral">&quot;outImg has size less than needed to draw img1&quot;</span> );
<a name="l00221"></a>00221     }
<a name="l00222"></a>00222     <span class="keywordflow">else</span>
<a name="l00223"></a>00223     {
<a name="l00224"></a>00224       outImg.create( size, CV_MAKETYPE( img1.depth( ), 3 ) );
<a name="l00225"></a>00225 
<a name="l00226"></a>00226       <span class="keywordflow">if</span>( img1.type( ) == CV_8U )
<a name="l00227"></a>00227         cv::cvtColor( img1, outImg, CV_GRAY2BGR );
<a name="l00228"></a>00228       <span class="keywordflow">else</span>
<a name="l00229"></a>00229         img1.copyTo( outImg );
<a name="l00230"></a>00230     }
<a name="l00231"></a>00231 
<a name="l00232"></a>00232     <span class="comment">// draw keypoints</span>
<a name="l00233"></a>00233     <span class="keywordflow">if</span>( !( flags &amp; cv::DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS ) )
<a name="l00234"></a>00234     {
<a name="l00235"></a>00235       drawKeypoints( outImg, keypoints1, outImg, singlePointColor,
<a name="l00236"></a>00236         flags + cv::DrawMatchesFlags::DRAW_OVER_OUTIMG );
<a name="l00237"></a>00237     }
<a name="l00238"></a>00238 
<a name="l00239"></a>00239     cv::RNG&amp; rng = cv::theRNG( );
<a name="l00240"></a>00240     <span class="keywordtype">bool</span> isRandMatchColor = matchColor == cv::Scalar::all( -1 );
<a name="l00241"></a>00241     vector&lt;DMatch&gt;::size_type total_size=matches1to2.size( );
<a name="l00242"></a>00242     <span class="comment">// draw matches</span>
<a name="l00243"></a>00243     <span class="keywordflow">for</span>( vector&lt;DMatch&gt;::size_type m = 0; m &lt; total_size; m++ )
<a name="l00244"></a>00244     {
<a name="l00245"></a>00245       <span class="keywordtype">int</span> i1 = matches1to2[ m ].trainIdx;
<a name="l00246"></a>00246       <span class="keywordtype">int</span> i2 = matches1to2[ m ].queryIdx;
<a name="l00247"></a>00247       <span class="keywordflow">if</span>( matchesMask.empty( ) || matchesMask[ m ] )
<a name="l00248"></a>00248       {
<a name="l00249"></a>00249         <span class="keyword">const</span> KeyPoint &amp;kp1 = keypoints1[ i1 ], &amp;kp2 = keypoints2[ i2 ];
<a name="l00250"></a>00250 
<a name="l00251"></a>00251         cv::Scalar color = isRandMatchColor ?
<a name="l00252"></a>00252           cv::Scalar( rng( 256 ), rng( 256 ), rng( 256 ) ) : matchColor;
<a name="l00253"></a>00253 
<a name="l00254"></a>00254         cv::Point center1( cvRound( kp1.pt.x ), cvRound( kp1.pt.y ) );
<a name="l00255"></a>00255         cv::Point center2( cvRound( kp2.pt.x ), cvRound( kp2.pt.y ) );
<a name="l00256"></a>00256         <span class="keywordtype">int</span> radius = 1;
<a name="l00257"></a>00257         cv::circle( outImg, center1, radius, color, 1, CV_AA );
<a name="l00258"></a>00258         <span class="comment">//cv::circle( outImg, center2, radius, color, 1, CV_AA );</span>
<a name="l00259"></a>00259         cv::line( outImg, center1, center2, color, 1, CV_AA );
<a name="l00260"></a>00260 
<a name="l00261"></a>00261       }
<a name="l00262"></a>00262     }
<a name="l00263"></a>00263 
<a name="l00264"></a>00264   }
<a name="l00265"></a>00265 
<a name="l00266"></a>00266 
<a name="l00267"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a3ef50b6097da42e1de0cc7df953a3ee2">00267</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a3ef50b6097da42e1de0cc7df953a3ee2">PointsMatcher::read</a>( <span class="keyword">const</span> cv::FileNode&amp; node,
<a name="l00268"></a>00268     <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html" title="A class used for matching descriptors that can be described as vectors in a finite-dimensional space...">PointsMatcher</a>&amp; points )
<a name="l00269"></a>00269   {
<a name="l00270"></a>00270     std::string myName=node.name( );
<a name="l00271"></a>00271     <span class="keywordflow">if</span>( myName != <span class="stringliteral">&quot;PointsMatcher&quot;</span> )
<a name="l00272"></a>00272       <span class="keywordflow">return</span>;<span class="comment">//this node is not for us...</span>
<a name="l00273"></a>00273 
<a name="l00274"></a>00274     <span class="comment">//This matcher need only point coordinates as the matcher is already loaded:</span>
<a name="l00275"></a>00275 
<a name="l00276"></a>00276     <span class="keywordflow">if</span>( node.empty( ) || !node.isSeq( ) )
<a name="l00277"></a>00277       CV_Error( CV_StsError, <span class="stringliteral">&quot;PointsMatcher FileNode is not correct!&quot;</span> );
<a name="l00278"></a>00278 
<a name="l00279"></a>00279     <span class="keywordtype">int</span> numImg=0;
<a name="l00280"></a>00280     cv::FileNodeIterator it = node.begin( ), it_end = node.end( );
<a name="l00281"></a>00281     <span class="keywordflow">while</span>( it != it_end )
<a name="l00282"></a>00282     {
<a name="l00283"></a>00283       Ptr&lt;PointsToTrack&gt; ptt_tmp = Ptr&lt;PointsToTrack&gt;( <span class="keyword">new</span> <a class="code" href="class_opencv_sf_m_1_1_points_to_track.html" title="This class can be used to store informations about point and features. This is an abstract class: you...">PointsToTrack</a>( numImg ));
<a name="l00284"></a>00284       cv::FileNode node_tmp = ( *it )[ <span class="stringliteral">&quot;PointsToTrack&quot;</span> ];
<a name="l00285"></a>00285       <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a3ef50b6097da42e1de0cc7df953a3ee2">PointsToTrack::read</a>( node_tmp, *ptt_tmp );
<a name="l00286"></a>00286       points.<a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>.push_back( ptt_tmp );
<a name="l00287"></a>00287       it++;
<a name="l00288"></a>00288       numImg++;
<a name="l00289"></a>00289     }
<a name="l00290"></a>00290   }
<a name="l00291"></a>00291 
<a name="l00292"></a><a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a8bfd19d26890875b956827cb9d873591">00292</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a8bfd19d26890875b956827cb9d873591">PointsMatcher::write</a> ( cv::FileStorage&amp; fs,
<a name="l00293"></a>00293     <span class="keyword">const</span> <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html" title="A class used for matching descriptors that can be described as vectors in a finite-dimensional space...">PointsMatcher</a>&amp; points )
<a name="l00294"></a>00294   {
<a name="l00295"></a>00295     vector&lt;PointsToTrack&gt;::size_type key_size = points.<a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>.size( );
<a name="l00296"></a>00296 
<a name="l00297"></a>00297     fs &lt;&lt; <span class="stringliteral">&quot;PointsMatcher&quot;</span> &lt;&lt; <span class="stringliteral">&quot;[&quot;</span>;
<a name="l00298"></a>00298 
<a name="l00299"></a>00299     <span class="keywordflow">for</span> ( vector&lt;PointsToTrack&gt;::size_type i=0; i &lt; key_size; i++ )
<a name="l00300"></a>00300     {
<a name="l00301"></a>00301       fs  &lt;&lt; <span class="stringliteral">&quot;{&quot;</span>;
<a name="l00302"></a>00302       <a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a8bfd19d26890875b956827cb9d873591">PointsToTrack::write</a>( fs, *points.<a class="code" href="class_opencv_sf_m_1_1_points_matcher.html#a62062498c4325863469d980c39baebc1" title="Vector of points used to compute matches...">pointCollection_</a>[ i ] );
<a name="l00303"></a>00303       fs  &lt;&lt; <span class="stringliteral">&quot;}&quot;</span>;
<a name="l00304"></a>00304     }
<a name="l00305"></a>00305     fs &lt;&lt; <span class="stringliteral">&quot;]&quot;</span>;
<a name="l00306"></a>00306   }
<a name="l00307"></a>00307 }
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Sun Aug 21 2011 16:45:52 for GSoC2011SfM by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
